package com.minelx.animator.animators;

import java.util.function.Supplier;

public class RepeatableAnimator implements Animator {

	private final Supplier<Animator> newGetter;

	private Animator animator;

	public RepeatableAnimator(Supplier<Animator> newGetter) {
		this.newGetter = newGetter;
	}

	@Override
	public void start() {
		stop();
		animator = newGetter.get();
		animator.start();
	}

	@Override
	public void stop() {
		if (!isRunning()) return;
		animator.stop();
	}

	@Override
	public boolean isRunning() {
		return animator != null && animator.isRunning();
	}
}
